package org.gbif.portal.struts;

import java.util.Map;

import org.gbif.ecat.cfg.DataDirConfig;
import org.gbif.portal.action.BaseAction;
import org.gbif.portal.model.Agent;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

/**
* An Interceptor that makes sure a user is currently logged in and returns a notLoggedIn otherwise
*/
public class RequireLoginInterceptor extends AbstractInterceptor{

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		Map session = invocation.getInvocationContext().getSession();
		Agent user = (Agent) session.get(DataDirConfig.SESSION_USER);
		if (user==null){
			return BaseAction.LOGIN_REQUIRED;
		}
		return invocation.invoke();
	}

}